package cn.hgpu.servlet;

import cn.hgpu.mapper.RoleMapper;
import cn.hgpu.pojo.Role;
import cn.hgpu.utils.MybatisUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/role/list")
public class RoleListServlet extends HttpServlet {
    //1.获取Rolemapper
    private RoleMapper roleMapper = MybatisUtils.getMapper(RoleMapper .class);

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //2.查询角色列表页面
        List<Role> list = roleMapper.selectAll();

        //3.将数据放到内存中
        req.setAttribute("list1", list);

        //4.跳转到/admin/list.jsp
        req.getRequestDispatcher("/role/list.jsp").forward(req, resp);
    }
}
